package actions;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import db.DbConnectionPool;
import forms.formAcctStatus;
import forms.formAddress;

public class acctStatusAction extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws DbException {
		//formAcctStatus iform = (formAcctStatus) form;
			//iform.setAcctName( request.getUserPrincipal().getName());
		boolean exist = false;
		String acctName = request.getUserPrincipal().getName(); 
		request.setAttribute("acctName", acctName);
		if( acctName != null)
		{
		try{
			Connection conn = DbConnectionPool.getConnection();
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery("SELECT user_status FROM user_status WHERE user_Name='"+request.getUserPrincipal().getName() +"'");
			if(rs.next())
			{
				if(rs.getBoolean(1))
					exist = true;
			}
			conn.commit();
			conn.close();
		}catch (SQLException ex) {
			throw new DbException(ex);
		} catch (NamingException ex) {
			throw new DbException(ex);
		}
		}
		if(exist)
			return mapping.findForward("exist");
		else
		
			return mapping.findForward("unexist");
	}
	

}
